package com.sc.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sc.entity.Summary;
import com.sc.service.SummaryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 许一
 * @since 2023-12-08 11:41:22
 */
@RestController
@RequestMapping("/summary")
public class SummaryController {
    @Resource
    private SummaryService summaryService;

    @GetMapping("/getOne")
    public Summary getOne(@RequestParam("warehouseId")  Long id) {
        //查数据库信息
        //查总数
        Long x1 = summaryService.getSum1(id);
        //查总出库
        Long x2 = summaryService.getSum2(id);
        //查未入库
        Long x3 = summaryService.getSum3(id);
        //查今日出库
        Long x4 = summaryService.getSum4(id);
        //查未进行单量
        Long x5 = summaryService.getSum5(id);
        summaryService.update(
                new LambdaUpdateWrapper<Summary>()
                .eq(Summary::getWarehouseId,id)
                .set(Summary::getTotalOrderQuantity,x1)
                .set(Summary::getTodayOutboundVolume,x4)
                .set(Summary::getTotalOutboundVolume,x2)
                .set(Summary::getUnshippedQuantity,x3)
                .set(Summary::getNotsingleVolumeWasMade,x5)
        );
        Summary summary = summaryService.getOne(
                new LambdaQueryWrapper<Summary>()
                .eq(Summary::getWarehouseId,id)
        );
        return summary;
    }

}
